<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class ArchiveResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        /** @var \App\Models\Archive $report */
        $report = $this;
        $photos = $report->photos;
        foreach ($photos as $key => $photo) {
            $photos[] = asset(\Storage::disk("public")->path($photo));
        }
        $statusMaps = ["派遣中", "已派遣", "未解决", "已解决", "已结案"];
        return [
            "photos" => $photos,
            "record_username" => $report->record_username,
            "record_num" => $report->record_num,
            "record_date" => $report->record_date->toDateString(),
            "record_people" => $report->record_people,
            "record_no" => $report->record_no,
            "message" => $report->message,
            "address" => $report->address,
            "latitude" => $report->latitude,
            "process" => $report->process,
            "longitude" => $report->longitude,
            "video" => $report->video ? asset(\Storage::disk("public")->path($report->video)) : null,
            'video_thumb' => $report->video_thumb ? asset(\Storage::disk("public")->path($report->video_thumb)) : null,
            'audio' => $report->audio ? asset(\Storage::disk("public")->path($report->audio)) : null,
            "user_id" => $report->user_id,
            "status" => $report->status,
            "status_label" => $statusMaps[$report->status]
        ];
    }
}
